home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / src / Tools / glimpsehttp / wwwlib / build.pl < prev    next >
Encoding:
Perl Script  |  1995-05-16  |  3.8 KB  |  158 lines

  1. #!/usr/local/bin/perl
  2. $searchurl = "http://search";
  3. #
  4. # Build HTML index recursively
  5. #
  6. # &build_descr(<directory>,<Title>[,"index"])
  7. #  - builds HTML index in given <directory>, top page has title <Title>.
  8. #    if third argument is given as "index", glimpseindex is called to build
  9. #    word index in this directory
  10. #
  11. # Uses files:
  12. #  $TEMPLATE - HTML index template
  13. #  do_bd - indexing program
  14. #  put_segment - auxilary program
  15. #
  16.  
  17. #  where your HTTPD stuff is located
  18. $HTTPD_HOME="/r/don/usr1/paul/httpd";
  19.  
  20. # Location of glimpse and glimpseindex, options for glimpseindex
  21. $GLIMPSE_LOC="/usr/paul/bin/glimpse";
  22. $GLIMPSEIDX_LOC="/usr/paul/bin/glimpseindex";
  23.  
  24. # server administrator name
  25. $adminname = "Paul Klark";
  26. # server administrator e-mail
  27. $adminaddress = "paul@cs.arizona.edu";
  28.  
  29. # index template
  30. $TEMPLATE="$HTTPD_HOME/wwwlib/template.bd";
  31. $DESCFILE=".description";
  32. # name of the index file
  33. $HTMLINDEX="ghindex.html";
  34.  
  35. &build_descr("/r/don/usr1/udi/archive","Test title");
  36. #
  37. # no configuration is needed below this line
  38. #
  39. sub build_descr {
  40.     local($dir,$toptitle,$doindex) = @_;
  41.     chdir $dir || die "Cannot chdir to $dir to build indices: $!\n";
  42.     open(TEMPLATE,$TEMPLATE) || die "Cannot open index template file ".
  43.         "$TEMPLATE: $!\n";
  44.     $outid = "FILE000";
  45.     &do_bd("",$toptitle);
  46.     close(TEMPLATE);
  47.     if ($doindex) {
  48.         # unlink <.glimpse_[^i]*>;
  49.         system("exec $GLIMPSEIDX_LOC $GLIMPSEIDX_OPT -H . . &");
  50.     }
  51. }
  52.  
  53. sub do_bd {
  54.     local($relpath,$title) = @_;
  55.     local($file,$thisdir,$desc,$dirfiles,$dirsize,$totfiles,$totsize);
  56.     local(%desc,$header,$OUT,$DIR,$fileshere,$dirshere);
  57.     $totfiles = 0;
  58.     $totsize = 0;
  59.     $thisdir = `pwd`;
  60.     chop $thisdir;
  61.     undef $dirshere;
  62.     undef $fileshere;
  63.     
  64.     $OUT = $outid;
  65.     $DIR = $outid;
  66.     $outid++;
  67.     open($OUT,">$HTMLINDEX") || die "Cannot open file ".
  68.         "$thisdir/$HTMLINDEX for writing: $!\n";
  69.     print $OUT "<HEAD><TITLE>$title</TITLE></HEAD>\n";
  70.     print $OUT "<BODY><H1>$title</H1>\n";
  71.     &put_segment($OUT,"PROLOG");
  72.     # slurp description file into array desc
  73.     if (open(DESC,$DESCFILE)) {
  74.         desc: while (<DESC>) {
  75.             # print verbatim any lines beginning with @
  76.             if (s/^@//) {
  77.                 print;
  78.                 next desc;
  79.             }
  80.             chop;
  81.             ($file,$desc) = split(/\t+/);
  82.             next desc unless $file =~ /^\w/;
  83.             $desc{$file} = $desc;
  84.         }
  85.         close(DESC);
  86.     }
  87.     opendir($DIR,".");
  88.     file: while ($file=readdir($DIR)) {
  89.         next if $file =~ /^\./;
  90.         next if $file eq $HTMLINDEX;
  91.         local($dev,$ino,$mode,$nlinsk,$uid,$gid,$rdev,$size) =
  92.             stat($file);
  93.         if (-d $file) {
  94.             print "subdirectory $file\n";
  95.             chdir $file || next file;
  96.             $desc = $desc{$file};
  97.             if ($desc) {
  98.                 $header = $desc;
  99.                 ($dirfiles,$dirsize) =
  100.                     &do_bd("$relpath/$file",$desc);
  101.             } else {
  102.                 # no description - make it up
  103.                 $desc = "$title/$file";
  104.                 ($dirfiles,$dirsize) =
  105.                     &do_bd("$relpath/$file",$desc);
  106.                 $header = "Directory '$file' (";
  107.                 $header .= "$dirfiles files, " if $dirfiles;
  108.                 $header .= "total $dirsize bytes)";
  109.             }
  110.             $totfiles += $dirfiles;
  111.             $totsize += $dirsize;
  112.             chdir $thisdir;
  113.             $dirshere = "<li><a href=\"".
  114.                 "$file/$HTMLINDEX\">$header</a>\n";
  115.         } else {
  116.             $totfiles += 1;
  117.             $totsize += $size;
  118.             $header = $desc{$file};
  119.             $header = "$file ($size bytes)" unless $header;
  120.             $fileshere .= "<li><a href=\"$file\">".
  121.                 "$header</a>\n";
  122.         }
  123.     }
  124.     closedir($DIR);
  125.     if ($dirshere) {
  126.         &put_segment($OUT,"PREDIR");
  127.         print $OUT $dirshere;
  128.         &put_segment($OUT,"POSTDIR");
  129.     }
  130.     &put_segment($OUT,"FORM");
  131.     if ($fileshere) {
  132.         &put_segment($OUT,"PREFILE");
  133.         print $OUT $fileshere;
  134.         &put_segment($OUT,"POSTFILE");
  135.     }
  136.     &put_segment($OUT,"EPILOG");
  137.     close($OUT);
  138.     return ($totfiles+1,$totsize);
  139. }
  140.  
  141. sub put_segment {
  142.     local($OUT,$label) = @_;
  143.     local($_,$flag);
  144.     seek(TEMPLATE,0,0);
  145.     $flag = 0;
  146.     line: while (<TEMPLATE>) {
  147.         next if /^#/;
  148.         if (/^@$label/) {
  149.             $flag = 1;
  150.             next line;
  151.         }
  152.         last line if $flag && /^@/;
  153.         next line unless $flag;
  154.         s/\$\w[\w_]*/$&/gee;
  155.         print $OUT $_;
  156.     }
  157. }
  158.